app.controller('blogListCtrl', ['$rootScope', '$scope', '$http', '$state', '$stateParams',
  function($rootScope, $scope, $http, $state, $stateParams) {
    var vm = this;
    if ($stateParams.id) {
      $http.get('/api/categorys/' + $stateParams.id)
        .success(function(res) {
          $rootScope.title = $rootScope.title + ' - ' + res.data.name;
          $http.get('/api/articles?code=' + res.data.code)
            .success(function(res) {
              vm.articles = res.data.rows;
            })
            .error(function(res) {
              vm.article = [];
            });
        });
    } else {
      $state.go('index');
    }
  }
]);
